<template>
	<div class="login_container">
		<el-dialog title="登录" :show-close="false" :visible.sync="dialogFormVisible" center width="30%">
			<div>
				<!--表单-->
				<el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0px" class="login_form">
					<el-form-item label="用户名" prop="username" :label-width="formLabelWidth">
						<el-input v-model="loginForm.username" placeholder="请输入用户名" prefix-icon="el-icon-user-solid"></el-input>
					</el-form-item>
					<el-form-item label="密   码" prop="password" :label-width="formLabelWidth">
						<el-input type="password" v-model="loginForm.password" placeholder="请输入密码" prefix-icon="el-icon-lock"></el-input>
					</el-form-item>
					<el-form-item label="验证码" prop="verifyCode" :label-width="formLabelWidth">
						<div class="verifyCode_box">
							<el-input v-model="loginForm.verifyCode" placeholder="请输入验证码" prefix-icon="el-icon-mobile" class="verifyCode"></el-input>
							<img src="../assets/img/msFXK1.gif" alt="" class="verifyCode_img">
						</div>
					</el-form-item>
				</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
				<el-button @click="resetForm('loginForm')">重置</el-button>
			</span>
			</div>
		</el-dialog>
	</div>
</template>

<script type="text/javascript">
	export default {
		name: 'Login',
		data() {
			return {
				formLabelWidth: "120px",
				dialogFormVisible: true,
				loginForm: {
					username: '',
					password: '',
					verifyCode: ''
				},
				loginRules: {
					username: [{
							required: true,
							message: '请输入用户名称',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 16,
							message: '长度在 3 到 16 个字符',
							trigger: 'blur'
						}
					],
					password: [{
							required: true,
							message: '请输入登录密码',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 16,
							message: '长度在 3 到 16 个字符',
							trigger: 'blur'
						}
					],
					verifyCode: [{
						required: true,
						message: '请输入验证码',
						trigger: 'blur'
					}]
				}
			};
		},
		methods: {
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.$router.push("/home");
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			}
		}
	}
</script>

<style scoped>
	.login_form {
		bottom: 0px;
		width: 100%;
		padding: 0px 20px;
		box-sizing: border-box;
	}

	.login_form .el-form-item {
		margin-left: -35px;
	}

	.verifyCode_box {
		display: flex;
	}

	.verifyCode {
		width: 50%;
		justify-content: left;
	}

	.verifyCode_img {
		width: 30%;
		height: 45px;
		margin-left: 50px;
		justify-content: flex-end;
	}
	.dialog-footer{
		margin:120px ;
	}
</style>
